

cc.Class({
    extends: cc.Component,
    properties: {
        PREFAB: cc.Prefab, //预制件
        parent: cc.Node,   //预制件实例化后所在的父节点
        zIndex: 0,
        // tasks: [cc.String],
    },

    onLoad() {
        if (!CC_EDITOR) {
            this.loadPrefab();
            // cc.director.on('drag')
        }
    },

    start() {
        this.getTask();
        // this.runTask2(1)
    },

    loadPrefab() {
        try {
            let node = cc.instantiate(this.PREFAB);
            node.zIndex = this.zIndex;
            node.position = cc.v2(0, 0);
            //不持久化到编辑器
            node._objFlags = cc.Object.Flags.DontSave;
            node.parent = this.parent.parent.getChildByName('Canvas') || this.node;
            this._godGuide = node.getComponent('GodGuide');
        }
        catch (error) {
            cc.error(this.PREFAB);
            cc.error(error);
        }
    },

    getTask() {
        this.taskGrp = [
            { args: "欢迎来到迷你特工队总部，迷你特工队员们。", cmd: "text", config: null, delayTime: 0, description: "点击按钮1", ends: null, taskId: 1, text: "这是一个text", textPos: null },
            { args: "刚接到消息，奈恩打算入侵小动物乐园，总部需要你们去保卫乐园防线。", cmd: "text", config: null, delayTime: 0, description: "点击按钮1", ends: null, taskId: 1, text: "这是一个text", textPos: null },
            { args: "快和伙伴们一起去阻止奈恩的邪恶计划！", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 1, text: "这是一个text", textPos: null },
            { args: "uiRoot/Cover/BottomBar/BottomBar/bottomNode/Team/Background", cmd: "finger", config: null, delayTime: 0, description: "关闭签到", ends: null, taskId: 1, text: "点击队伍按钮", textPos: null },

            { args: "uiRoot/Cover/equipmentPage/equipmentPage/pageView/view/content/equipPageItem1/showDetailBtn", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 1, text: "点击强化", textPos: -100 },
            { args: "uiRoot/Cover/equipDetailPage/equipDetailPage/lvUp", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 1, text: "点击升级", textPos: null },
            { args: "升级装备需要一定的素材和金币，可以去战斗中获取资源。", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 1, text: "这是一个text", textPos: null },
            { args: "uiRoot/Cover/equipDetailPage/equipDetailPage/close", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 1, text: "关闭升级页面", textPos: null },

            { args: "uiRoot/Cover/equipmentPage/equipmentPage/twoBtn/right", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击查看其它特工", textPos: -100 },
            { args: "uiRoot/Cover/equipmentPage/equipmentPage/fightNode/inFight0", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击位置", textPos: -100 },
            { args: "uiRoot/Cover/equipmentPage/equipmentPage/pageView/view/content/equipPageItem1/funcBtn", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击上场", textPos: -100 },
            // { args: "uiRoot/Cover/equipmentPage/equipmentPage/twoBtn/right", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击查看其它特工", textPos: -100 },
            // { args: "uiRoot/Cover/equipmentPage/equipmentPage/fightNode/inFight1", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击位置", textPos: -100 },
            // { args: "uiRoot/Cover/equipmentPage/equipmentPage/pageView/view/content/equipPageItem1/funcBtn", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击上场", textPos: -100 },
            // { args: "uiRoot/Cover/equipmentPage/equipmentPage/twoBtn/right", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击查看其它特工", textPos: -100 },
            // { args: "uiRoot/Cover/equipmentPage/equipmentPage/fightNode/inFight3", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击位置", textPos: -100 },
            // { args: "uiRoot/Cover/equipmentPage/equipmentPage/pageView/view/content/equipPageItem1/funcBtn", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 3, text: "点击上场", textPos: -100 },
            { args: "uiRoot/Cover/BottomBar/BottomBar/bottomNode/Card/Background", cmd: "finger", config: null, delayTime: 0, description: "关闭签到", ends: null, taskId: 3, text: "点击卡片按钮", textPos: null },

            { args: "这是新开发的科技装备，赶紧装备起来去试试看吧", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 4, text: "这是一个text", textPos: null },
            { args: "uiRoot/Cover/skillPage/skillPage/bagScroll/view/content/skillItem", cmd: "finger", config: null, delayTime: 0, description: "关闭签到", ends: null, taskId: 4, text: "点击选择技能", textPos: null },
            { args: "uiRoot/Cover/skillPage/skillPage/threeBtns/useBtn", cmd: "finger", config: null, delayTime: 0, description: "关闭签到", ends: null, taskId: 4, text: "点击装备技能", textPos: null },
            { args: "uiRoot/Cover/BottomBar/BottomBar/bottomNode/Fight/Background", cmd: "finger", config: null, delayTime: 0, description: "关闭签到", ends: null, taskId: 4, text: "返回主页面", textPos: null },
            { args: "uiRoot/Cover/bottomSec/bottomSec/start", cmd: "finger", config: null, delayTime: 0.2, description: "", ends: null, taskId: 4, text: "点击开始游戏", textPos: null },

            { args: "Content/Tower", cmd: "rect", config: null, delayTime: 0, description: "敌人靠近后，会攻击我方防线", ends: null, taskId: 5, text: "敌人靠近后，会攻击我方防线", textPos: null },
            { args: "uiRoot/Base/TopInfo/TopInfo/Avatar", cmd: "rect", config: null, delayTime: 0, description: "防线被攻击后，会减少我方生命，生命降至0后结束战斗", ends: null, id: 2, taskId: 5, text: "防线被攻击后，会减少我方生命，生命降至0后结束战斗", textPos: null },
            { args: "接下来，让我们消灭所有敌人！", cmd: "text", config: null, delayTime: 0, description: "点击按钮1", ends: null, taskId: 5, text: "这是一个text", textPos: null },
            { args: "就是这个时机，快使用技能！", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 5, text: "这是一个text", textPos: null },
            { args: "uiRoot/Base/SkillBox/SkillBox/skill_1", cmd: "finger", config: null, delayTime: 0.1, description: "", ends: null, taskId: 5, text: "快使用技能！", textPos: null },
            { args: "你现在已经能独当一面了，我也不能时时照顾你。", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 6, text: "这是一个text", textPos: null },
            { args: "之后的战斗需要多做准备，可以去商店购买战需物品。", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 6, text: "这是一个text", textPos: null },
            { args: "uiRoot/Cover/RightBar/RightBar/layout/letter", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 6, text: "点击商店", textPos: null },
            { args: "uiRoot/Cover/storePage/storePage/scroll/view/content/storeItem", cmd: "finger", config: null, delayTime: 0, description: "点击按钮2", ends: null, taskId: 6, text: "点击物品", textPos: null },
            { args: "uiRoot/Cover/confirmPage/confirmPage/buy", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 6, text: "点击购买", textPos: null },
            // { args: "uiRoot/Cover/getStoreItemPage/getStoreItemPage/getBtn", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 6, text: "领取", textPos: null },
            { args: "uiRoot/Cover/storePage/storePage/close", cmd: "finger", config: null, delayTime: 0, description: "", ends: null, taskId: 6, text: "点击关闭", textPos: null },
            { args: "小伙子好好努力！", cmd: "text", config: null, delayTime: 0, description: "text", ends: null, taskId: 6, text: "这是一个text", textPos: null },
            // { args: "这是一个text", cmd: "text", config: null, delayTime: 0, description: "点击按钮1", ends: null, id: 1, taskId: 1, text: "这是一个text", textPos: null },
            // { args: "Canvas/parent/touchNode", cmd: "drag", delayTime: null, description: "拖拽", ends: "Canvas/pos", id: 4, taskId: 1, text: "拖拽", textPos: null }
        ]
    },

    runTask2(num, num2) {
        let grp = []
        let task = {
            taskId: num,
            name: '一个测试',
            debug: true,
            autorun: false,
            steps: []
        }
        for (let i = 0; i < this.taskGrp.length; i++) {
            if (this.taskGrp[i].taskId == num) {
                grp.push(this.taskGet(this.taskGrp[i]))
            }
        }
        task.steps = grp
        this._godGuide.init()
        this._godGuide.setTask(task);
        this._godGuide.run();
    },






    taskGet(info) {
        let task = { "desc": "点击", "config": info.config }
        let som
        switch (info.cmd) {
            case 'text':
                som = { "command": { 'cmd': "text", "args": `${info.args}`, 'pos': `${info.textPos}` } }
                Object.assign(task, som)
                break
            case 'finger':
                som = { "command": { 'cmd': "finger", "args": `${info.args}`, 'text': `${info.text}`, 'pos': `${info.textPos}` } }
                Object.assign(task, som)
                break
            case 'drag':
                som = { "command": { 'cmd': "drag", "args": `${info.args}`, "ends": `${info.ends}`, "text": info.text, 'pos': `${info.textPos}` } }
                Object.assign(task, som)
                break
            case 'rect':
                som = { "command": { 'cmd': "rect", "args": `${info.args}`, "text": info.text, 'pos': `${info.textPos}` } }
                Object.assign(task, som)
                break
        }
        if (info.delayTime) {
            let time = { "delayTime": info.delayTime }
            Object.assign(task, time)
        }
        // console.log(task)
        return task
    },

});